import math

#region math
def distance(x1, y1, x2, y2):
    return math.sqrt(((x2 - x1) ** 2) + ((y2 - y1) ** 2))

def midpoint(x1, y1, x2, y2):
    return ((x1 + x2)/2, (y1 + y2)/2)

# https://www.geeksforgeeks.org/check-whether-the-point-x-y-lies-on-a-given-line/
def point_is_on_line(m, c, x, y):

    # If (x, y) satisfies the
    # equation of the line
    if (y == ((m * x) + c)):
        return True

    return False

def point_near_line(px, py, x1, y1, x2, y2, tolerance):
    # Calculate the distance from point (px, py) to the line segment (x1, y1) - (x2, y2)
    numerator = abs((y2 - y1) * px - (x2 - x1) * py + x2 * y1 - y2 * x1)
    denominator = math.sqrt((y2 - y1)**2 + (x2 - x1)**2)
    distance = numerator / denominator

    return distance <= tolerance
#endregion
